package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhAgentArea;
import com.ruoyi.zsyh.service.IZsyhAgentAreaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 大区会长管辖区域Controller
 * 
 * @author yuexl
 * @date 2021-12-10
 */
@Controller
@RequestMapping("/zsyh/agentarea")
public class ZsyhAgentAreaController extends BaseController
{
    private String prefix = "zsyh/agentarea";

    @Autowired
    private IZsyhAgentAreaService zsyhAgentAreaService;

    @RequiresPermissions("zsyh:agentarea:view")
    @GetMapping()
    public String agentarea()
    {
        return prefix + "/agentarea";
    }

    /**
     * 查询大区会长管辖区域列表
     */
    @RequiresPermissions("zsyh:agentarea:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhAgentArea zsyhAgentArea)
    {
        startPage();
        List<ZsyhAgentArea> list = zsyhAgentAreaService.selectZsyhAgentAreaList(zsyhAgentArea);
        return getDataTable(list);
    }

    /**
     * 导出大区会长管辖区域列表
     */
    @RequiresPermissions("zsyh:agentarea:export")
    @Log(title = "大区会长管辖区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhAgentArea zsyhAgentArea)
    {
        List<ZsyhAgentArea> list = zsyhAgentAreaService.selectZsyhAgentAreaList(zsyhAgentArea);
        ExcelUtil<ZsyhAgentArea> util = new ExcelUtil<ZsyhAgentArea>(ZsyhAgentArea.class);
        return util.exportExcel(list, "大区会长管辖区域数据");
    }

    /**
     * 新增大区会长管辖区域
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存大区会长管辖区域
     */
    @RequiresPermissions("zsyh:agentarea:add")
    @Log(title = "大区会长管辖区域", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhAgentArea zsyhAgentArea)
    {
        return toAjax(zsyhAgentAreaService.insertZsyhAgentArea(zsyhAgentArea));
    }

    /**
     * 修改大区会长管辖区域
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhAgentArea zsyhAgentArea = zsyhAgentAreaService.selectZsyhAgentAreaById(id);
        mmap.put("zsyhAgentArea", zsyhAgentArea);
        return prefix + "/edit";
    }

    /**
     * 修改保存大区会长管辖区域
     */
    @RequiresPermissions("zsyh:agentarea:edit")
    @Log(title = "大区会长管辖区域", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhAgentArea zsyhAgentArea)
    {
        return toAjax(zsyhAgentAreaService.updateZsyhAgentArea(zsyhAgentArea));
    }

    /**
     * 删除大区会长管辖区域
     */
    @RequiresPermissions("zsyh:agentarea:remove")
    @Log(title = "大区会长管辖区域", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhAgentAreaService.deleteZsyhAgentAreaByIds(ids));
    }
}
